#include"game.h"
#include<bits/stdc++.h>
using namespace std;
const int N=509;
int n,cnt,p[N],vis[N];
vector<int> ans,now;
vector<int> to[N];
void dfs(int u){
	vis[u]=1;
	p[++p[0]]=u;
	for(int v:to[u])
		if(!vis[v])
			dfs(v);
	return;
}
vector<int> guess(int nn,int limit){
	n=nn; ans.resize(n);
	for(int i=1;i<=n;i++)
		ans[i-1]=i;
	random_shuffle(ans.begin(),ans.end());
	now=ans; cnt=count(now);
	int cntnow;
	for(int i=0;i<n;i++){
		if(to[i].size()==2) continue;
		for(int j=i+1;j<n;j++){
			if(to[j].size()==2) continue;
			swap(now[i],now[j]);
			cntnow=count(now);
			swap(now[i],now[j]);
			if(cntnow>cnt)
				to[i].push_back(j),to[j].push_back(i);
			if(to[i].size()==2) break;
		}
	}
	for(int i=0;i<n;i++){
		if(vis[i]) continue;
		p[0]=0; dfs(i);
		if(p[0]==1) continue;
		if(p[0]==2){ swap(ans[p[1]],ans[p[2]]); cnt+=2; now=ans; continue; }
		if(p[0]==3){
			swap(now[p[1]],now[p[2]]); swap(now[p[1]],now[p[3]]);
			cntnow=count(now);
			if(cntnow==cnt+3){
//				cerr<<endl<<i<<endl;
				swap(ans[p[1]],ans[p[2]]),swap(ans[p[1]],ans[p[3]]);
			}
			else{
//				cerr<<endl<<"!!! "<<i<<endl;
				swap(ans[p[1]],ans[p[2]]),swap(ans[p[2]],ans[p[3]]);
			}
			now=ans;
			cnt+=3;
			continue;
		}
		swap(now[p[1]],now[p[2]]); swap(now[p[1]],now[p[3]]);
		cntnow=count(now);
		if(cntnow==cnt+2)
			for(int j=2;j<=p[0];j++)
				swap(ans[p[1]],ans[p[j]]);
		else
			for(int j=1;j<p[0];j++)
				swap(ans[p[j]],ans[p[j+1]]);
		cnt+=p[0]; now=ans;
	}
	return ans;
}